<?php

namespace App\Controller\Admin\Ad;

use App\Controller\Admin\BaseController;
use App\Dao\Ad\AdDao;
use Hyperf\Di\Annotation\Inject;
use Yj\Apidog\Annotation\ApiController;
use Yj\Apidog\Annotation\FormData;
use Yj\Apidog\Annotation\PostApi;

/**
 * @ApiController(prefix="admin/ad/ad")
 */
class AdController extends BaseController
{

    /**
     * @Inject()
     * @var AdDao
     */
    protected $adDao;

    /**
     * @PostApi(path="lists",description="")
     */
    public function lists(){
        $data =  $this->adDao->lists();
        _SUCCESS($data);
    }

    /**
     * @PostApi(path="add")
     * @FormData(key="name",rule="required")
     * @FormData(key="price",rule="required")
     */
    public function add(){
        $data = $this->getValidatorData();
        $this->adDao->create($data->toArray());
        _SUCCESS();
    }

    /**
     * @PostApi(path="edit")
     * @FormData(key="name",rule="required")
     * @FormData(key="price",rule="required")
     * @FormData(key="id",rule="required")
     */
    public function edit(){
        $data = $this->getValidatorData();
        $this->adDao->edit($data->get('id'),$data->except('id'));
        _SUCCESS();
    }

    /**
     * @PostApi(path="delete")
     * @FormData(key="id",rule="required")
     */
    public function delete(){
        $data = $this->getValidatorData();
        $this->adDao->del($data->get('id'));
        _SUCCESS();
    }
}